<template>
  <div class="home-container">
    <el-card class="welcome-card">
      <template #header>
        <div class="card-header">
          <span>欢迎使用轻客管家系统</span>
        </div>
      </template>
      <div class="welcome-content">
        <p>当前时间：{{ currentTime }}</p>
        <p>登录用户：小传</p>
      </div>
    </el-card>

    <div class="stats-container">
      <el-row :gutter="20">
        <el-col :span="6">
          <el-card class="stat-card">
            <div class="stat-item">
              <div class="stat-number">128</div>
              <div class="stat-label">今日新增线索</div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card">
            <div class="stat-item">
              <div class="stat-number">56</div>
              <div class="stat-label">待跟进商机</div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card">
            <div class="stat-item">
              <div class="stat-number">258</div>
              <div class="stat-label">客户总数</div>
            </div>
          </el-card>
        </el-col>
        <el-col :span="6">
          <el-card class="stat-card">
            <div class="stat-item">
              <div class="stat-number">¥286,500</div>
              <div class="stat-label">本月销售额</div>
            </div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <div class="charts-container">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-card class="chart-card">
            <template #header>
              <div class="card-header">
                <span>销售趋势分析</span>
              </div>
            </template>
            <div class="chart-placeholder">图表占位区域</div>
          </el-card>
        </el-col>
        <el-col :span="12">
          <el-card class="chart-card">
            <template #header>
              <div class="card-header">
                <span>线索转化漏斗</span>
              </div>
            </template>
            <div class="chart-placeholder">图表占位区域</div>
          </el-card>
        </el-col>
      </el-row>
    </div>

    <div class="todo-container">
      <el-card class="todo-card">
        <template #header>
          <div class="card-header">
            <span>待办任务</span>
          </div>
        </template>
        <el-table :data="todoList" style="width: 100%">
          <el-table-column prop="id" label="序号" width="80" />
          <el-table-column prop="title" label="任务标题" />
          <el-table-column prop="deadline" label="截止时间" width="180" />
          <el-table-column prop="priority" label="优先级" width="100">
            <template #default="scope">
              <el-tag :type="getPriorityType(scope.row.priority)">
                {{ scope.row.priority }}
              </el-tag>
            </template>
          </el-table-column>
          <el-table-column prop="status" label="状态" width="100" />
          <el-table-column label="操作" width="100">
            <template #default>
              <el-button type="primary" size="small">处理</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-card>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'

// 当前时间
const currentTime = ref('')

// 待办任务列表
const todoList = ref([
  { id: 1, title: '跟进重要客户', deadline: '2025-01-25 12:00', priority: '高', status: '待处理' },
  { id: 2, title: '整理月度报表', deadline: '2025-01-26 18:00', priority: '中', status: '进行中' },
  { id: 3, title: '参加团队会议', deadline: '2025-01-25 15:00', priority: '中', status: '待处理' },
  { id: 4, title: '回复客户邮件', deadline: '2025-01-24 17:00', priority: '高', status: '待处理' },
  { id: 5, title: '更新销售计划', deadline: '2025-01-27 18:00', priority: '低', status: '未开始' }
])

// 根据优先级获取标签类型
const getPriorityType = (priority) => {
  const typeMap = {
    '高': 'danger',
    '中': 'warning',
    '低': 'info'
  }
  return typeMap[priority] || 'default'
}

// 更新当前时间
const updateTime = () => {
  const now = new Date()
  currentTime.value = now.toLocaleString('zh-CN')
}

onMounted(() => {
  updateTime()
  setInterval(updateTime, 1000)
})
</script>

<style scoped>
.home-container {
  padding: 0;
}

.welcome-card {
  margin-bottom: 20px;
}

.welcome-content {
  font-size: 16px;
  line-height: 1.8;
}

.stats-container {
  margin-bottom: 20px;
}

.stat-card {
  height: 120px;
}

.stat-item {
  height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.stat-number {
  font-size: 32px;
  font-weight: bold;
  color: #1890ff;
  margin-bottom: 10px;
}

.stat-label {
  font-size: 16px;
  color: #606266;
}

.charts-container {
  margin-bottom: 20px;
}

.chart-card {
  height: 300px;
}

.chart-placeholder {
  height: calc(100% - 40px);
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: #f5f7fa;
  color: #909399;
}

.todo-container {
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>